package com.jlu.iml;

import com.jlu.p2pserver.IFileQuery;
import com.jlu.utils.DBManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

/**
 * @Author freedom
 * @DATE 2017/5/24 0024 20:52.
 * see   服务器发送文件接口实现类
 */
public class FileQueryImpl implements IFileQuery {

    private static final Logger log = Logger.getLogger(FileQueryImpl.class.getName());
    private List<Map<String, Object>> mList;
    private List<String> sList;


    @Override
    public List<String> queryFiles() {
        // 返还服务器文件名
        mList = DBManager.fileQuery();
        sList = new ArrayList<String>();

        if (mList.size() > 0) {
            for (Map<String, Object> map :
                    mList) {
                String fileName = map.get("file_name").toString();
                sList.add(fileName);
            }
            if (sList.size() > 0) {
                log.info("发送文件名成功");
            } else {
                log.info("发送文件名失败");
            }

        } else {
            log.info("服务器没有可发送文件");
        }
        return sList;
    }

}
